//
//  XLGDownloadSocketOperation.m
//  etionLib
//
//  Created by JingXing Wu on 12-5-12.
//  Copyright (c) 2012年 GuangZhouXuanWu. All rights reserved.
//

#import "XLGDownloadSocketOperation.h"

#import "XLGDownloadManager.h"

//#import "FsfilesObj.h"

@implementation XLGDownloadSocketOperation

-(BOOL)startItem
{
    [super startItem];
 
    @autoreleasepool
    {
        m_packfile=[CPackFileDown new];
        m_packfile.m_delegate=self;
        
        //fileversion/fileid/filename.ext
//        NSArray* ar = [_mi.URL componentsSeparatedByString:@"/"];
//        CFsfilesObj* file = [CFsfilesObj new];
//        file.m_szFileid = [ar objectAtIndex:1];
//        file.m_szFilename = _mi.title;
//        file.m_nEnterprisenumber = [XLGContext context].m_nEnterprisenumber;
//        file.m_szFileversion = [ar objectAtIndex:0];
//        [m_packfile Start:file];
    }
    
    return NO;
}

-(NSUInteger)FileLength:(NSUInteger)nLength
{
    _fileTotalSize=nLength-_fileCurrentSize;
    
    [self initFileData];
    
    return _fileCurrentSize;
}

-(void)FileDownloadPack:(NSData*)data
{
    [self writeDataToFile:data];
}

-(void)FileDownloadError:(NSInteger)nResult error:(NSError*)error
{
    [super downloadError];
}

-(void)FileDownloadFinish
{
    [super downloadFinished];
}

-(void)Cleanup
{
    [m_packfile Cancel];
    [super cleanup];
}

-(void)stopDownload
{
	[m_packfile Cancel];
	[self Cleanup];
}

-(void)dealloc
{
    [m_packfile release_mm];
    [super dealloc];
}

@end
